import * as API from "@api/index";
import {Injectable} from "@angular/core";
import {HttpService} from "@core/http/http.service";
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from "@angular/router";
import {AuthService} from "@shared/service/auth/auth.service";

@Injectable()
export class FeedResolver implements Resolve<any> {
  constructor(
    private _httpService: HttpService,
    private _authService: AuthService
  ) {}

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    const userId = route.params['userId'] || this._authService.getUserId();
    const url = API.GET_USER_FEED_URL + `?userId=${userId}&page=1&rows=10`;
    return this._httpService.get(url).map(res => res.json())
  }
}
